import Vue from 'vue'
import Vuex from 'vuex'
import { setInfo, getInfo } from '@/utils/storage'
Vue.use(Vuex)

export default ({
  namespaced: true,
  state () {
    return {
      userInfo: getInfo() // 获取本地token 没有有默认值
    }
  },
  getters: {
  },
  mutations: {
    setUserInfo (state, obj) {
      state.userInfo = obj
      // 本地存储持久化
      setInfo((obj))
    }
  },
  actions: {
    // 退出登录
    logout (context) {
      context.commit('setUserInfo', {})
      context.commit('cart/setCartList', [], { root: true })
    }
  },
  modules: {
  }
})
